# Contributor: Fernando Casas Schossow <casasfernando@outlook.com>
# Maintainer: Fernando Casas Schossow <casasfernando@outlook.com>
pkgname=ocaml-gettext
_pkgname=gettext
pkgver=0.4.2
pkgrel=3
pkgdesc="OCaml library for i18n"
url="https://github.com/gildor478/ocaml-gettext"
arch="all !riscv64 !loongarch64" # ocaml
license="LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception"
makedepends="
	autoconf
	automake
	chrpath
	docbook-xsl
	dune
	gettext-dev
	libxml2
	libxslt
	ocaml
	ocaml-camlp4-dev
	ocaml-camomile-dev
	ocaml-compiler-libs
	ocaml-cppo
	ocaml-fileutils
	ocaml-fileutils-dev
	ocaml-findlib-dev
	ocaml-seq-dev
	ocaml-ocamldoc
	ocaml-stdlib-shims
"
subpackages="$pkgname-dev $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/gildor478/ocaml-gettext/archive/v$pkgver.tar.gz"
options="!check" # there is no test suite/unit tests since tests requires camomile

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	export OCAMLPATH=/usr/lib/ocaml
	# Build only gettext, as gettext-stub requires dune-configurator
	dune build -p gettext @install
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--prefix=/usr \
		--libdir=/usr/lib/ocaml \
		gettext

	cd "$pkgdir"
	mkdir -vp usr/share/doc
	mv -v usr/doc/"$_pkgname" \
		usr/share/doc/"$pkgname"
	mv -v usr/man usr/share/
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
fb89be8d8d9e0ed9327b81a0c81c884ff3f1a97e46b475ef8084abded5c84a256de05d5aa0f42be94f43ab438276a4506af726b6950e4161359a9616fb5832ec  ocaml-gettext-0.4.2.tar.gz
"
